package com.oop.demo;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * @author miao
 * @version 1.0
 * @date 2025/4/14 10:43
 * @description
 */
public class Demo1 {
    public static void main(String[] args) {
        Handleable handleable = new Handleable() {
            @Override
            public String handle(String num) {
                // 取整数部分
                BigDecimal bigDecimal = new BigDecimal(num);

                return bigDecimal.divide(new BigDecimal("1"), 0, RoundingMode.HALF_UP).toString();
            }
        };
        String str=handleable.handle("23.2345678");// 使用 lambda 表达式创建 Handleable 对象
        System.out.println("str = " + str);// 输出结果：str = 23
        Handleable handleable2 = new Handleable() {
            @Override
            public String handle(String num) {
                BigDecimal bigDecimal = new BigDecimal(num);// new BigDecimal(num);

                return bigDecimal.divide(new BigDecimal("1"), 4, 4).toString();// 四舍五入
            }
        };
        String str2 = handleable2.handle("23.23456789");// 使用 lambda 表达式创建 Handleable 对象
        System.out.println("str2 = " + str2);

    }
    public static void main2(String[] args) {
        BigDecimal bigDecimal = new BigDecimal("123.4562313");
        BigDecimal divide = bigDecimal.divide(new BigDecimal("1"), 2, RoundingMode.HALF_UP);
        System.out.println("divide = " + divide);
    }
    public static void main1(String[] args) {
        Integer integer = 10;
        int num = integer;

        System.out.println("num = " + num);
        int num3 = integer.intValue();
        System.out.println("num3 = " + num3);
        int num2 = 20;
        Integer integer2 = num2;
        System.out.println("integer2 = " + integer2);
        Integer num4 = Integer.valueOf(num2); // 使用 Integer.valueOf 替代 new Integer
        System.out.println("num4 = " + num4);
        Integer num5 = Integer.valueOf(num2); // 修复拼写错误并移除 new
        System.out.println("num5 = " + num5); // 实际使用 num5 避免未使用警告
        int num6 = 10;
        String str = num6 + "";
        System.out.println("str = " + str);
        String str2 = String.valueOf(num6);
        System.out.println("str2 = " + str2);
        String str3 ="123";
        int num7 = Integer.parseInt(str3);
        System.out.println("num7 = " + num7);

    }
}


